<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>prencar: D:/Workspace/Arduino/prencar/StateMaschine.cpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="prencar.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">prencar
   &#160;<span id="projectnumber">1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('_state_maschine_8cpp.html','');
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">D:/Workspace/Arduino/prencar/StateMaschine.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_state_maschine_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;Arduino.h&quot;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &quot;<a class="code" href="_state_maschine_8h.html">StateMaschine.h</a>&quot;</span>
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 <a class="code" href="class_state_maschine.html">StateMaschine</a> <a class="code" href="class_state_maschine.html#ae63367f6117a93b862973b7756ce515c" title="Static reference to the singleton object.">StateMaschine::_instance</a>; 
<a name="l00005"></a>00005 <span class="keywordtype">boolean</span> <a class="code" href="class_state_maschine.html#a9c60433a0d4dba03bfe5422c0896b4ba">StateMaschine::_instanceCreated</a> = <span class="keyword">false</span>;
<a name="l00006"></a>00006 
<a name="l00011"></a><a class="code" href="class_state_maschine.html#a908a6b51448036bc23a7cd76acfcfbe0">00011</a> <a class="code" href="class_state_maschine.html">StateMaschine</a>* <a class="code" href="class_state_maschine.html#a908a6b51448036bc23a7cd76acfcfbe0">StateMaschine::getInstance</a>()
<a name="l00012"></a>00012 {
<a name="l00013"></a>00013   <span class="keywordflow">if</span> ( !<a class="code" href="class_state_maschine.html#a9c60433a0d4dba03bfe5422c0896b4ba">_instanceCreated</a> ){
<a name="l00014"></a>00014     <a class="code" href="class_state_maschine.html#ae63367f6117a93b862973b7756ce515c" title="Static reference to the singleton object.">_instance</a> = <a class="code" href="class_state_maschine.html#a869746d152d0a38b8d6142da3b420e85">StateMaschine</a>();
<a name="l00015"></a>00015     <a class="code" href="class_state_maschine.html#a9c60433a0d4dba03bfe5422c0896b4ba">_instanceCreated</a> = <span class="keyword">true</span>;
<a name="l00016"></a>00016 
<a name="l00017"></a>00017     <span class="comment">//do the configuration stuff so that a call to begin() from the outside of the</span>
<a name="l00018"></a>00018     <span class="comment">//class is not necessary</span>
<a name="l00019"></a>00019     <a class="code" href="class_state_maschine.html#ae63367f6117a93b862973b7756ce515c" title="Static reference to the singleton object.">_instance</a>.<a class="code" href="class_state_maschine.html#acdadfde97fc8449c816c1b489e2f4a22">begin</a>();
<a name="l00020"></a>00020   }
<a name="l00021"></a>00021   <span class="keywordflow">return</span> &amp;<a class="code" href="class_state_maschine.html#ae63367f6117a93b862973b7756ce515c" title="Static reference to the singleton object.">_instance</a>;
<a name="l00022"></a>00022 }
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 
<a name="l00028"></a><a class="code" href="class_state_maschine.html#a869746d152d0a38b8d6142da3b420e85">00028</a> <a class="code" href="class_state_maschine.html#a869746d152d0a38b8d6142da3b420e85">StateMaschine::StateMaschine</a>()
<a name="l00029"></a>00029 {
<a name="l00030"></a>00030   <a class="code" href="class_state_maschine.html#adbdb287052ba80eb22fd4a910edc0115">parcoursState</a> = <a class="code" href="_state_maschine_8h.html#ad5f3c64cf1a6afd0af12270f4a539ce8a3dcefcfc73c46cd08fedd1d3c0dbaad1">notStarted</a>;
<a name="l00031"></a>00031 }
<a name="l00032"></a>00032 
<a name="l00036"></a><a class="code" href="class_state_maschine.html#acdadfde97fc8449c816c1b489e2f4a22">00036</a> <span class="keywordtype">void</span> <a class="code" href="class_state_maschine.html#acdadfde97fc8449c816c1b489e2f4a22">StateMaschine::begin</a>(){
<a name="l00037"></a>00037   <a class="code" href="class_state_maschine.html#a375a5c409935687eab5d7185c25b2e97" title="The reference to the serial communication class.">_com</a> = <a class="code" href="class_state_maschine.html#a908a6b51448036bc23a7cd76acfcfbe0">Communication::getInstance</a>();
<a name="l00038"></a>00038   <a class="code" href="class_state_maschine.html#a1739f27286f50fbc99a6212c029c79d5" title="The reference to the configuration class.">_conf</a> = <a class="code" href="class_state_maschine.html#a908a6b51448036bc23a7cd76acfcfbe0">Configuration::getInstance</a>();
<a name="l00039"></a>00039   <a class="code" href="class_state_maschine.html#a91050d9a782c56bbceb4f51255707685" title="The reference to the move class.">_move</a> = <a class="code" href="class_state_maschine.html#a908a6b51448036bc23a7cd76acfcfbe0">Move::getInstance</a>();
<a name="l00040"></a>00040   <a class="code" href="class_state_maschine.html#a3307f4f89ffd7ebb3faa55467c32a71d">lineFollow</a>.<a class="code" href="class_line_follow.html#afac0ad1ff185b7e5f9b47428cb2e5e48">begin</a>();
<a name="l00041"></a>00041 }
<a name="l00042"></a>00042 
<a name="l00048"></a><a class="code" href="class_state_maschine.html#a1095131aa8e6e9537f481b5f425395e2">00048</a> <span class="keywordtype">void</span> <a class="code" href="class_state_maschine.html#a1095131aa8e6e9537f481b5f425395e2">StateMaschine::doJob</a>(){
<a name="l00049"></a>00049 
<a name="l00050"></a>00050   <a class="code" href="class_state_maschine.html#a5551d00a5224f595833b75969c2ca64a">checkCommands</a>();
<a name="l00051"></a>00051 
<a name="l00052"></a>00052   delay(1000);
<a name="l00053"></a>00053   <span class="keywordflow">if</span>(<a class="code" href="class_state_maschine.html#adbdb287052ba80eb22fd4a910edc0115">parcoursState</a> == <a class="code" href="_state_maschine_8h.html#ad5f3c64cf1a6afd0af12270f4a539ce8a96474cef925f487adb48d8db38ee3455">followingFirstLine</a>){
<a name="l00054"></a>00054     <a class="code" href="class_state_maschine.html#a3307f4f89ffd7ebb3faa55467c32a71d">lineFollow</a>.<a class="code" href="class_line_follow.html#a93ff35747f2ae3bb26998f07243afc3c">doJob</a>();
<a name="l00055"></a>00055   }
<a name="l00056"></a>00056 }
<a name="l00057"></a>00057 
<a name="l00062"></a><a class="code" href="class_state_maschine.html#a5551d00a5224f595833b75969c2ca64a">00062</a> <span class="keywordtype">void</span> <a class="code" href="class_state_maschine.html#a5551d00a5224f595833b75969c2ca64a">StateMaschine::checkCommands</a>(){
<a name="l00063"></a>00063   <a class="code" href="class_command.html" title="A Command object represents a command sent from the host software.">Command</a> c;
<a name="l00064"></a>00064 
<a name="l00065"></a>00065   <span class="comment">//the following commands are only available, if the parcours is not started</span>
<a name="l00066"></a>00066   <span class="keywordflow">if</span>(<a class="code" href="class_state_maschine.html#adbdb287052ba80eb22fd4a910edc0115">parcoursState</a> == <a class="code" href="_state_maschine_8h.html#ad5f3c64cf1a6afd0af12270f4a539ce8a3dcefcfc73c46cd08fedd1d3c0dbaad1">notStarted</a> || <a class="code" href="class_state_maschine.html#adbdb287052ba80eb22fd4a910edc0115">parcoursState</a> == <a class="code" href="_state_maschine_8h.html#ad5f3c64cf1a6afd0af12270f4a539ce8aaf38e35232eb6728664f98c8110d11a4">finished</a>){
<a name="l00067"></a>00067     <span class="comment">//check for command 200</span>
<a name="l00068"></a>00068     <span class="keywordflow">if</span>(<a class="code" href="class_state_maschine.html#a375a5c409935687eab5d7185c25b2e97" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a17bff838a0404ae06482f17bcecd3784">getAndRemoveCommandFromReadyCommands</a>(&amp;c, 200)){
<a name="l00069"></a>00069       <a class="code" href="class_state_maschine.html#a3307f4f89ffd7ebb3faa55467c32a71d">lineFollow</a>.<a class="code" href="class_line_follow.html#a9db172747e4457a6b01f8d27ed41ac39" title="Calibrates the sensors.">calibrateSensors</a>();
<a name="l00070"></a>00070     }
<a name="l00071"></a>00071 
<a name="l00072"></a>00072     <span class="comment">//check for command 300</span>
<a name="l00073"></a>00073     <span class="keywordflow">if</span>(<a class="code" href="class_state_maschine.html#a375a5c409935687eab5d7185c25b2e97" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a17bff838a0404ae06482f17bcecd3784">getAndRemoveCommandFromReadyCommands</a>(&amp;c, 300)){
<a name="l00074"></a>00074       <a class="code" href="class_state_maschine.html#aaca597f41ba735fce3ef0eb06e4fda18">startParcours</a>();
<a name="l00075"></a>00075     }
<a name="l00076"></a>00076   }
<a name="l00077"></a>00077 
<a name="l00078"></a>00078   <span class="comment">//check for command 301</span>
<a name="l00079"></a>00079   <span class="keywordflow">if</span>(<a class="code" href="class_state_maschine.html#a375a5c409935687eab5d7185c25b2e97" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a17bff838a0404ae06482f17bcecd3784">getAndRemoveCommandFromReadyCommands</a>(&amp;c, 301)){
<a name="l00080"></a>00080     <a class="code" href="class_state_maschine.html#ae028d25d4b664d805e0f516a49cfdb23">stopParcours</a>();
<a name="l00081"></a>00081   }
<a name="l00082"></a>00082 }
<a name="l00083"></a>00083 
<a name="l00087"></a><a class="code" href="class_state_maschine.html#aaca597f41ba735fce3ef0eb06e4fda18">00087</a> <span class="keywordtype">void</span> <a class="code" href="class_state_maschine.html#aaca597f41ba735fce3ef0eb06e4fda18">StateMaschine::startParcours</a>(){
<a name="l00088"></a>00088   <a class="code" href="class_state_maschine.html#a3307f4f89ffd7ebb3faa55467c32a71d">lineFollow</a>.<a class="code" href="class_line_follow.html#a5f3e76e795bacff24be60b7f65d84d94">startIt</a>();
<a name="l00089"></a>00089   <a class="code" href="class_state_maschine.html#a5b9f3dfb795afbb28c1beeaa6f6512a4">changeState</a>(<a class="code" href="_state_maschine_8h.html#ad5f3c64cf1a6afd0af12270f4a539ce8a96474cef925f487adb48d8db38ee3455">followingFirstLine</a>);
<a name="l00090"></a>00090 }
<a name="l00091"></a>00091 
<a name="l00095"></a><a class="code" href="class_state_maschine.html#ae028d25d4b664d805e0f516a49cfdb23">00095</a> <span class="keywordtype">void</span> <a class="code" href="class_state_maschine.html#ae028d25d4b664d805e0f516a49cfdb23">StateMaschine::stopParcours</a>(){
<a name="l00096"></a>00096   <a class="code" href="class_state_maschine.html#a91050d9a782c56bbceb4f51255707685" title="The reference to the move class.">_move</a>-&gt;<a class="code" href="class_move.html#a237261f2dd8fc115129f0ba998f13183">performFastStop</a>();
<a name="l00097"></a>00097   <a class="code" href="class_state_maschine.html#a5b9f3dfb795afbb28c1beeaa6f6512a4">changeState</a>(<a class="code" href="_state_maschine_8h.html#ad5f3c64cf1a6afd0af12270f4a539ce8a3dcefcfc73c46cd08fedd1d3c0dbaad1">notStarted</a>);
<a name="l00098"></a>00098 }
<a name="l00099"></a>00099 
<a name="l00104"></a><a class="code" href="class_state_maschine.html#a5b9f3dfb795afbb28c1beeaa6f6512a4">00104</a> <span class="keywordtype">void</span> <a class="code" href="class_state_maschine.html#a5b9f3dfb795afbb28c1beeaa6f6512a4">StateMaschine::changeState</a>(<a class="code" href="_state_maschine_8h.html#ad5f3c64cf1a6afd0af12270f4a539ce8">TParcoursState</a> newState){
<a name="l00105"></a>00105   <a class="code" href="class_state_maschine.html#adbdb287052ba80eb22fd4a910edc0115">parcoursState</a> = newState;
<a name="l00106"></a>00106   <a class="code" href="class_state_maschine.html#a375a5c409935687eab5d7185c25b2e97" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(100, newState);
<a name="l00107"></a>00107 }
<a name="l00108"></a>00108 
<a name="l00109"></a>00109 
<a name="l00110"></a>00110 
<a name="l00111"></a>00111 
<a name="l00112"></a>00112 
<a name="l00113"></a>00113 
<a name="l00114"></a>00114 
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="_state_maschine_8cpp.html">StateMaschine.cpp</a>      </li>

    <li class="footer">Generated on Tue Apr 3 2012 18:43:12 for prencar by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.0 </li>
   </ul>
 </div>


</body>
</html>
